package com.example.demo.testOne;

import com.example.demo.pojo.dto.People;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @description 并行流与map的测试
 *
 * @author lilinchun
 * @date 2023/12/13
 */
public class demo18 {


    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add(null);
        System.out.println(list);
        List<People> list1 = new ArrayList<>();
        People people = new People(1, "2");
        People people1 = new People(2, "2");
        People people2 = new People(3, "2");
        People people3 = new People(4, "2");
        People people4 = new People(5, null);
        list1.add(people1);
        list1.add(people);
        list1.add(people2);
        list1.add(people3);
        list1.add(people4);
        HashMap<Integer, String> map1 = new HashMap<>();
        list1.stream().parallel().map(x -> {
            map1.put(x.getId(), x.getName());
            return x;
        }).collect(Collectors.toList());
        map1.put(null, null);
        System.out.println(map1.toString());

        HashMap<Integer, String> map2 = new HashMap<>();
        list1.stream().map(x -> {
            map2.put(x.getId(), x.getName());
            return x;
        }).collect(Collectors.toList());
        System.out.println(map2.toString());
        Map<Integer, String> map = list1.stream().collect(Collectors.toMap(People::getId, People::getName, (x, y) -> x));
        System.out.println(map.toString());
    }
}
